<template>
  <div class="ai-monitoring">
    <el-card class="search-card" v-show="showSearch" style="margin-bottom: 15px; border-radius: 8px; width: 100%">
      <el-form @submit.native.prevent :model="queryParams" ref="queryForm" :inline="true" style="margin-bottom: -18px; padding: 3px 0 0 0">
<!--        <el-form-item prop="cs">-->
<!--          <el-input v-model="queryParams.cs" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />-->
<!--        </el-form-item>-->
        <el-form-item label="事件时间" label-width="80px">
          <el-date-picker
            v-model="dateRange"
            style="width: 240px"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <div style="float: right">
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('search') }}</el-button>
          <el-button class="button-ty" icon="el-icon-refresh" @click="resetQuery">{{ $t('reset') }}</el-button>
        </div>
      </el-form>
    </el-card>

    <el-card class="search-card" style="border-radius: 8px">
      <el-row :gutter="10" style="margin-bottom: 16px">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
      </el-row>
      <div class="data-table">
        <el-table v-loading="loading" :data="tableData" :row-key="getRowKey" :border="false" ref="multipleTable" :max-height="580">
          <el-table-column prop="majorCodeName" label="安全分类" align="center"></el-table-column>
          <el-table-column prop="eventName" label="事件名称" align="center"></el-table-column>
          <el-table-column label="风险等级" align="center" prop="riskLevel">
            <template slot-scope="scope">
              <el-tag :type="getRiskType(scope.row.riskLevel)">{{ scope.row.riskLevel }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="channelName" label="摄像头名称" align="center"></el-table-column>
          <el-table-column prop="snapshotUrl" label="快照" align="center">
            <template slot-scope="scope">
              <el-image :src="scope.row.snapshotUrl" :preview-src-list="getBigSnap(scope.row.snapshotUrl)" fit="cover" style="width: 28px; height: 28px">
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"></i>
                </div>
              </el-image>
            </template>
          </el-table-column>
          <el-table-column label="事件状态" align="center" prop="status" >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.event_confirmed" :value="scope.row.confirmed" />
            </template>
          </el-table-column>
          <el-table-column prop="eventTime" label="事件时间" align="center"></el-table-column>
          <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width"
                           width="180">
            <template v-slot="scope">
              <el-button size="small" type="text" icon="el-icon-edit" @click="handleConfirm(scope.row)">确认
              </el-button>
              <el-button size="small" type="text" icon="el-icon-delete" @click="handleCancel(scope.row)">取消
              </el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination style="margin-bottom: 20px" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
      </div>
    </el-card>
  </div>
</template>

<script>
import { getEventList, getConfirmEvent } from '@/api/private/aiMonitoring';
export default {
  name: "AiMonitoring",
  dicts: ['event_confirmed'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        tenantId: 1,
        pageNum: 1,
        pageSize: 10,
        filtered: 1,
      },
      dateRange: [],
      tableData: [],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 风险等级映射到预设类型
    getRiskType(riskLevel) {
      switch (riskLevel) {
        case "A":
          return "danger";
        case "B":
          return "warning";
        case "C":
          return "success";
        default:
          return "default"; // 默认类型（灰色）
      }
    },
    // 查询列表
    getList() {
      this.loading = true;
      getEventList(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      this.loading = false;
    },
    // 表单重置
    reset() {
      this.form = {
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm('queryForm');
      this.handleQuery();
    },
    handleConfirm(row) {
      const eventName = row?.eventName || "未知事件";
      const data = {
        confirmed: "1",
        eventId: row.eventId,
      }
      this.$modal
        .confirm(this.$t('confirmEventMsg', { eventName: eventName }))
        .then(function () {
          return getConfirmEvent(data);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess(this.$t('确认事件成功'));
        })
        .catch(() => {});
    },
    handleCancel(row) {
      const eventName = row?.eventName || "未知事件";
      const data = {
        confirmed: "0",
        eventId: row.eventId,
      }
      this.$modal
        .confirm(this.$t('cancelEventMsg', { eventName: eventName }))
        .then(function () {
          return getConfirmEvent(data);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess(this.$t('取消事件成功'));
        })
        .catch(() => {});
    },
    getRowKey(row){
      return row.id;
    },
    getBigSnap: function (snapshotUrl) {
      return [snapshotUrl];
    },
  }
}
</script>

<style lang="scss" scoped>
.ai-monitoring {
  z-index: 1;
  min-height: calc(100vh - (72 / 1080 * 100vh));
  background: rgba(0,11,61,0.8);
  padding: 10px;

  ::v-deep .el-form-item__label {
    color: #ffffff;
  }
}
.search-card {
  background: rgba(0,11,61,0.8);
  color: #fff;
  border-width: #{px2vw(1)};
  border-style: solid;

  // 2. 渐变边框背景（核心样式，颜色部分无需转换）
  border-image: linear-gradient(
      180deg,
      rgba(22, 93, 255, 0),
      rgba(22, 93, 255, 0.59),
      rgba(22, 93, 255, 1)
  ) 1 1;

  ::v-deep .el-input__inner {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(22, 93, 255, 0.5);
    color: #fff; /* 文字颜色 */
  }
  ::v-deep .el-range-editor--medium .el-range-input {
    background: none;
    color: #fff; /* 文字颜色 */
  }
}
.button-ty {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(22, 93, 255, 0.5);
  color: #fff; /* 文字颜色 */
}
::v-deep .top-right-btn .custom-button[data-v-38ed449c] {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(22, 93, 255, 0.5);
  color: #fff; /* 文字颜色 */
}
.data-table {
  ::v-deep .el-table {
    border: none !important;
  }

  ::v-deep .el-table__fixed-right-patch {
    height: 0 !important;
  }

  /* 2. 表头底下线条 */
  ::v-deep .el-table th.el-table__cell.is-leaf {
    border-bottom: none;
  }

  /* 2. 表头背景（列标题区域） */
  ::v-deep .el-table tr {
    background: rgba(22,93,255);
  }
  /* 2. 表头字体大小（列标题区域） */
  ::v-deep .el-table th.el-table__cell>.cell {
    //font-size: px2font(16);
    //border-right: none !important; /* 移除单元格右侧边框 */
    //border-left: none !important; /* 移除单元格左侧边框（通常默认无，但保险起见） */
  }

  ::v-deep .el-button--text {
    color: #ffffff;
  }

  /* 3. 表格体背景（数据行区域） */
  /* 3.1 普通行背景 */
  ::v-deep .el-table__body-wrapper,
  ::v-deep .el-table__row {
    background: rgba(0,11,61,0.79) !important; /* 普通行背景（示例：白色） */
  }
  /* 3.1 普通行字体大小 */
  ::v-deep .el-table td.el-table__cell div {
    //font-size: px2font(14);
  }
  /* 表格体单元格背景（确保与行背景一致） */
  ::v-deep .el-table__cell {
    //background-color: inherit !important; /* 继承行背景 */
    background: rgba(0,11,61,0.79) !important; /* 表格体文字颜色（可选） */
    border-right: none !important; /* 移除单元格右侧边框 */
    border-left: none !important; /* 移除单元格左侧边框（通常默认无，但保险起见） */
    border: 1px solid rgba(255,255,255,0.1);
    font-family: PingFang SC, PingFang SC;
    font-weight: 400;
    color: rgba(255,255,255,0.9);
    text-align: center;
    font-style: normal;
    text-transform: none;
  }

  /* 4. 行 hover 状态背景（鼠标悬停时） */
  ::v-deep .el-table__row:hover {
    background: rgba(22,93,255,0.4) !important; /* hover 背景（示例：淡蓝） */
  }

  /* 5. 表格边框颜色（可选：与背景色协调） */
  ::v-deep .el-table__border,
  ::v-deep .el-table-cell {
    background: rgba(0,11,61,0.79) !important; /* 边框颜色（示例：浅灰） */
  }

  ::v-deep .el-table--border::after, .el-table--group::after {
    width: 0 !important;
  }

  ::v-deep .el-table__fixed-right::before {
    height: 0 !important;
  }

  ::v-deep .el-table::before {
    height: 0 !important;
  }


  /* 1. 分页组件整体文字颜色（基础设置） */
  ::v-deep .el-pagination {
    color: #ffffff !important; /* 默认文字颜色（示例：深灰色） */
  }

  ::v-deep input.el-input__inner {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(22, 93, 255, 0.5);
    color: #ffffff;
  }

  ::v-deep button.btn-prev {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(22, 93, 255, 0.5);
    color: #ffffff;
  }

  ::v-deep button.btn-next {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(22, 93, 255, 0.5);
    color: #ffffff;
  }

  /* 2. 页码按钮文字颜色 */
  ::v-deep .el-pager li {
    color: #ffffff !important; /* 普通页码文字 */
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(22, 93, 255, 0.5) !important;
  }

  /* 3. 当前选中页码的文字颜色 */
  ::v-deep .el-pager li.active {
    background-color: #409EFF !important;
    color: #ffffff !important; /* 选中页码文字（通常与背景色对比） */
  }

  /* 4. 上一页/下一页按钮文字颜色 */
  ::v-deep .el-pagination__prev,
  ::v-deep .el-pagination__next {
    color: #ffffff !important; /* 箭头按钮文字 */
  }

  /* 5. 禁用状态（如第一页的"上一页"）的文字颜色 */
  ::v-deep .el-pagination__prev.is-disabled,
  ::v-deep .el-pagination__next.is-disabled {
    color: #ffffff !important; /* 禁用状态文字（示例：浅灰色） */
  }

  /* 6. 总条数/跳转文本的颜色（如"共 100 条"） */
  ::v-deep .el-pagination__total,
  ::v-deep .el-pagination__jump {
    color: #ffffff !important; /* 说明文字颜色 */
  }

  ::v-deep .pagination-container {
    background: none;
    margin-top: px2vh(10);
    margin-bottom: px2vh(20);
  }

  ::v-deep .el-input--medium .el-input__inner {
    height: 28px;
  }
}
//::v-deep .el-input__inner {
//  background: rgba(255, 255, 255, 0.1);
//  border-color: rgba(22, 93, 255, 0.5);
//  color: #fff; /* 文字颜色 */
//}

</style>
